package com.ruoyi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

@Component
public class UdpServer {

    @PostConstruct
    public static void init() {
        try(DatagramSocket socket=new DatagramSocket(8085)) {
            byte[] buffer = new byte[1024];
            DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
            System.out.println("UDP+++++++++++++启动");
            socket.receive(packet);
            byte[] data = packet.getData();
            String receivedData = new String(packet.getData()).trim();
            // 使用您的 JSON 转换工具将字符串转换为 SysContracts 对象
//            SysContracts contracts = JSONUtil.toBean(receivedData, SysContracts.class);
//            SysContracts contracts = JSONUtil.toBean(s, SysContracts.class);
//            System.out.println("BUY:"+contracts);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}